﻿using System;
using System.Collections;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using Rison.DataAccess.Data.Common;

namespace Rison.Web
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class OnlineChat : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            try
            {
                string newsId = loadNewsId();
                string content = Convert.ToString(loadNewsContent(newsId));
                content = content.Replace("\n","\\n");
                content = content.Replace("\r", "\\r");
                content = content.Replace("\"","\\\"");
                context.Response.Write(String.Format("var _onlineChat = {{content:\"{0}\",key:\"{1}\"}};", content, newsId));
            }
            catch (Exception e)
            {
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
        private string loadNewsId()
        {
            string sql = "select InfoGuid from vwInfoCategory_Show t where t.CategoryID='6e11cbe3-1c9e-4a2b-9453-0c0a0b869a5c'";
            DataSet ds = DbAccess.executeQuery(sql);
            return ds.Tables[0].Rows[0][0].ToString();

        }
        private string loadNewsContent(string newsId)
        {
            string sql = String.Format("select [Content] from Information t where t.InfoGuid='{0}'",newsId);
            DataSet ds = DbAccess.executeQuery(sql);
            return ds.Tables[0].Rows[0][0].ToString();
        }

    }
}
